include Java

require "raw_classifier_strings"
require "classifier_pool"
require "peer_ranking_service"
require "component"
require "T:/Files/weka/dist/weka.jar"
require "running_parameters"
require "log"
require "j_time"
require "string"

import "java.io.FileReader"
import "weka.core.Instances"
import "weka.core.Utils"
import "weka.classifiers.Evaluation"
import "weka.classifiers.meta.Vote"

#
data_set_root_folder = "T:/Files/uci_binary_datasets"
splited_data_set_root_folder = "#{data_set_root_folder}/3_1_1"
data_set = "breast-cancer.arff"
#data_set = "breast-w.arff"
current_fold = 1

train_file = "#{splited_data_set_root_folder}/#{data_set}/#{current_fold}/training.arff"
train = Instances.new( FileReader.new( train_file ) )
train.setClassIndex( train.numAttributes - 1 )

query_file = "#{splited_data_set_root_folder}/#{data_set}/#{current_fold}/query.arff"
query = Instances.new( FileReader.new( query_file ) )
query.setClassIndex( query.numAttributes - 1 )

test_file = "#{splited_data_set_root_folder}/#{data_set}/#{current_fold}/test.arff"
test = Instances.new( FileReader.new( test_file ) )
test.setClassIndex( test.numAttributes - 1 )

#
RawClassifierStrings.set_raw_classifier_strings()


#
puts( "<num_of_raw_classifier_strings>: #{RawClassifierStrings.num_of_raw_classifier_strings}" )
pis = []
for recommended_peer_index in 0..( RawClassifierStrings.num_of_raw_classifier_strings - 1 )
  ensemble_classifier = Vote.new()
  vote_options = "-S 1 "
  classifier_str = RawClassifierStrings.raw_classifier_strings[ recommended_peer_index ]
  vote_options = vote_options + "-B \"#{ classifier_str.nest }\""
  vote_options = vote_options + " "
  vote_options.chop!
  vote_options = vote_options + " -R AVG"

  ensemble_classifier.setOptions( Utils.splitOptions( vote_options ) )
  ensemble_classifier.buildClassifier( train )
  eval = Evaluation.new( train )
  eval.evaluateModel( ensemble_classifier, test )
  metric = "pctCorrect()"
  case metric
  when "pctCorrect()"
    pis << [ eval.pctCorrect(), recommended_peer_index, RawClassifierStrings.raw_classifier_strings[ recommended_peer_index ], "-" ]
  when "weightedAreaUnderROC()"
    puts eval.weightedAreaUnderROC()
  when "weightedFalseNegativeRate()"
    puts eval.weightedFalseNegativeRate()
  when "weightedFalsePositiveRate()"
    puts eval.weightedFalsePositiveRate()
  when "weightedFMeasure()"
    puts eval.weightedFMeasure()
  when "weightedPrecision()"
    puts eval.weightedPrecision()
  when "weightedRecall()"
    puts eval.weightedRecall()
  when "weightedTrueNegativeRate()"
    puts eval.weightedTrueNegativeRate()
  when "weightedTruePositiveRate()"
    puts eval.weightedTruePositiveRate()
  end
end
puts( pis.sort )